package com.zac.junit.theories;



public class Utility {

	/*String a = "";
	int aLength = a.length();
	List b = new ArrayList();
	int bLength = b.size();
	Set c = new HashSet();
	int cLength = c.size();
	Map d = new HashMap();
	int dLength = d.size();
	int[] f = new int[10];
	int fLength = f.length;*/
	
	public static int binarySearch(int[] a, int target){
		int low = 0;
		int high = a.length - 1;
		
		while(low <= high){
			//int mid = (low + high) / 2
			/* Changes are that the sum of low and high is greater
			 * than Integer.MAX_VALUE(which is 2(31)-1 in Java).It
			 * overflows into a negative number and, of course, stays
			 * negative when divided by 2...
			**/
			int mid = safelyDividedBy2(low, high);
			int midVal = a[mid];
			
			if(midVal < target)
				low = mid + 1;
			else if (midVal > target)
				high = mid - 1;
			else
				return mid;
		}
		return -1;
	}
	
	//Best practice; help method
	public static int safelyDividedBy2(int low, int high){
		return (low + high) >>> 1;
	}
	
	public static void tryingSomething(){
		
		boolean m = true;
		if( m == false )
			System.out.println("False");
		else
			System.out.println("True");
		
	}
	
	public static void main(String[] args) {
		tryingSomething();
	}
	
}
